package com.meizi.experimentcode;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.google.common.base.Charsets;
import com.google.common.hash.Hashing;
import com.meizi.exception.RenException;

import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author Administration
 * @date 2021/11/9 - 21:43 - 星期二
 * @project lambda
 * @package com.meizi.config
 * @by 晨
 */
public class sign {
    public static String sign(List<String> values, String ticket) {
        if (values == null) {
            throw new NullPointerException("values is null");
        }
        values.removeAll(Collections.singleton(null));// remove null
        values.add(ticket); java.util.Collections.sort(values);
        StringBuilder sb = new StringBuilder();
        for (String s : values) { sb.append(s);
        }
        return Hashing.sha1().hashString(sb,
                Charsets.UTF_8).toString().toUpperCase();
    }

    public static void main(String[] args) throws ParseException {
        List<String> stringList = new ArrayList<>();
        stringList.add("1.0.0");
        stringList.add("IDAXXXXX");
        //stringList.add("XO99Qfxlti9iTVgHAjwvJdAZKN3nMuUhrsPdPlPVKlcyS50N6tlLnfuFBPIucaMS");
        stringList.add("kHoSxvLZGxSoFsjxlbzEoUzh5PAnTU7T");
        stringList.add("userID19959248596551");

        String s = "XO99Qfxlti9iTVgHAjwvJdAZKN3nMuUhrsPdPlPVKlcyS50N6tlLnfuFBPIucaMS";
        String sign = sign(stringList, s);
        int length = sign.length();
        System.out.println(length);
        System.out.println(sign);


        String ss = "sp";
        Long doctirId = 123456789L;
        Date date = new Date();
        DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
        String format = dateFormat.format(date);
        Date parse = dateFormat.parse(format);
        long time = parse.getTime();
        StringBuilder stringBuilder = new StringBuilder();
        StringBuilder append = stringBuilder.append(ss).append(doctirId).append(time);
        System.out.println(append);
        System.out.println(time);
        System.out.println(format);

        System.out.println("++++++++++++++差集差集差集差集差集差集差集差集");
        List<Integer> sss = new ArrayList<>();
        sss.add(1);
        sss.add(2);
        sss.add(3);
        sss.add(4);
        sss.add(6);
        List<Integer> ssssss = new ArrayList<>();
        ssssss.add(3);
        ssssss.add(5);
        ssssss.add(2);
        ssssss.add(1);
        ssssss.add(4);
        List<Integer> collect = ssssss.stream().filter((x) -> !sss.contains(x)).collect(Collectors.toList());
        collect.forEach(System.out::println);
        System.out.println("++++++++++++++++++++++差集差集差集差集差集差集");

        Float sellPrice = 1.23F;
        BigDecimal bigDecimal = new BigDecimal(sellPrice.toString());
        bigDecimal = bigDecimal.setScale(0,BigDecimal.ROUND_DOWN);
        System.out.println(bigDecimal.floatValue());

        System.out.println("++++++++++++++++++++++++++++++++++++++++");
        List<Aaaaaa> list = new ArrayList<>();
        Aaaaaa aa = new Aaaaaa();
        aa.setAge(6);
        Aaaaaa aa1 = new Aaaaaa();
        aa1.setAge(10);
        Aaaaaa aa2 = new Aaaaaa();
        aa2.setAge(2);
        aa2.setName("不知道");
        Aaaaaa aa3 = new Aaaaaa();
        aa3.setAge(3);
        Aaaaaa aa4 = new Aaaaaa();
        aa4.setAge(9);
        Aaaaaa aa5 = new Aaaaaa();
        aa5.setAge(16);
        Aaaaaa aa6 = new Aaaaaa();
        aa6.setAge(18);
        Aaaaaa aa7 = new Aaaaaa();
        aa7.setAge(20);
        list.add(aa);
        list.add(aa1);
        list.add(aa2);
        list.add(aa3);
        list.add(aa4);
        list.add(aa5);
        list.add(aa6);
        list.add(aa7);
        /*Collections.sort(list, new Comparator<Aaaaaa>() {
            @Override
            public int compare(Aaaaaa o1, Aaaaaa o2) {
                return o2.getAge() - o1.getAge();
            }
        });*/
        list.sort(Comparator.comparingInt(Aaaaaa::getAge).reversed());
        System.out.println(list);


        System.out.println("+++++++++++++++++++++++565555");

        BigDecimal consultFee =new BigDecimal("1000").setScale(0, BigDecimal.ROUND_DOWN);
        int compareTo = consultFee.compareTo(new BigDecimal("0"));
        int compare = consultFee.compareTo(new BigDecimal("1000"));
        if (compareTo <= 0 && compare >= 1) {
            throw new RenException().setMsg("咨询费得大于 0 小于 1000！！");
        }


        System.out.println("\\\\\\\\\\\\\\\\\\\\\\");
        long currentTime = System.currentTimeMillis() + 30 * 60 * 1000;

        Date date1 = new Date(currentTime);

        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        System.out.println(df.format(date1));


        System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
        // 失败患者的名字
        String failName = "";
        StringBuffer stringBuffer = new StringBuffer();
        for (int i = 0; i < 10; i++) {
            failName = stringBuffer.append(",").append(i).toString();
        }
        if (StringUtils.isNotEmpty(failName)) {
            failName = failName.substring(1);
        }
        System.out.println(failName);


        System.out.println("使用日历类 Calendar");
        Date date2 = new Date();
        System.out.println(df.format(date2));
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date()); // 获取当前时间
        calendar.add(Calendar.MINUTE,30);
        Date calendarTime = calendar.getTime();
        System.out.println(df.format(calendarTime));

    }
}
